-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Perf} Delay importing MSIAuthenticationWrapper and check_version_compatibility #14331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
add to S173 |
| try: | ||
| # Import in the `for` loop because `allowed_extensions` can be []. In such case we | ||
| # don't need to import `check_version_compatibility` at all. | ||
| from azure.cli.core.extension.operations import check_version_compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing a module in a for loop is not a good practice.
How much can it benefit from importing in this for loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can import module as many times as you want in one Python program, no matter what module it is. Every subsequent import after the first accesses the cached module instead of re-evaluating it. So there is no performance penalty.
In reply to: 454774982 [](ancestors = 454774982)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a tricky part. I just want to eliminate an extra if allowed_extensions:. Python has an import cache which will handle "import in a for loop" nicely.
jsntcy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
qianwens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
| is_windows, is_wsl | ||
| from azure.cli.core.cloud import get_active_cloud, set_cloud_subscription | ||
|
|
||
| from .adal_authentication import MSIAuthenticationWrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Fix regressions introduced by
check_version_compatibilityandrequestsexpiresInkey error in cloud shell login credentials for track 2 SDK related commands #14187, which unconditionally importsMSIAuthenticationWrapperandazure.core.credentialsThis PR delays the imports and brings
az versionto its normal speed.Testing Guide